package com.superb.common.database.mybatis.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.superb.common.database.mybatis.mapper.SuperbMapper;
import com.superb.common.database.mybatis.service.SuperbIService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 回收站、删除数据恢复、真删除实现
 * @Author: ajie
 * @CreateTime: 2024-05-23 14:24
 */
public class SuperbServiceImpl<M extends SuperbMapper<T>, T> extends ServiceImpl<M, T> implements SuperbIService<T> {

    @Override
    public List<T> delPage() {
        return baseMapper.delPage();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean recoveryByBatchId(List<String> list) {
        if (CollectionUtils.isEmpty(list)) {
            return false;
        }
        int batch = 0;
        for (String id : list) {
            batch = baseMapper.updateDel(id);
        }
        return batch > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByBatchId(List<String> list) {
        if (CollectionUtils.isEmpty(list)) {
            return false;
        }
        int batch = 0;
        for (String id : list) {
            batch = baseMapper.realDelete(id);
        }
        return batch > 0;
    }

}
